package com.mojo.web.controller;

import com.mojo.web.kafka.MyKafkaProducer;
import com.mojo.web.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * restAPI示例
 *
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2021, 广州九尾信息科技有限公司
 * @date 2021/10/18 19:18
 */
@RestController
public class RestControllerDemo {
    @Autowired
    private MyKafkaProducer myKafkaProducer;

    @PostMapping("user")
    public String saveUser(@RequestParam String name) {
        System.out.println(name);
        return "save-user";
    }

    @PutMapping("user")
    public String putUser() {
        return "put-user";
    }

    @GetMapping("user/{age}")
    public Map<String, Object> getUser(@PathVariable Integer age, @RequestParam String name,
                                       @RequestHeader(value = "Content-Type", required = false) String header) {
        System.out.println("age:" + age);
        System.out.println("name:" + name);
        System.out.println("header:" + header);
        HashMap<String, Object> map = new HashMap<>();
        map.put("age", age);
        map.put("name", name);
        map.put("header", header);
        return map;

    }

    @GetMapping("user")
    public User getUser(@RequestParam(required = false) String name) {
        User user = new User();
        user.setName("mojo");
        user.setAge(18);
        System.out.println(name);
        return user;
    }

    @GetMapping("kafka")
    public void kafkaDemo(@RequestParam String message) {
        //myKafkaProducer.send(message);
        myKafkaProducer.myOutput(message);
    }



}
